// src/stores/user.js
import { defineStore } from 'pinia'

export const useUserStore = defineStore('user', {
  state: () => ({
    token: localStorage.getItem('token') || '',
    userId: '',
    userInfo: {}
  }),
  actions: {
    // 保存用户登录信息
    setUserInfo(token, userId, info = {}) {
      this.token = token
      this.userId = userId
      this.userInfo = info
      localStorage.setItem('token', token)
      localStorage.setItem('userId', userId)
    },
    // 清除用户信息（退出登录）
    clearUserInfo() {
      this.token = ''
      this.userId = ''
      this.userInfo = {}
      localStorage.removeItem('token')
      localStorage.removeItem('userId')
    }
  }
})